const Axios = require('axios')

const https = Axios.create({
    timeout: 8000
})


// 两个拦截器现在都没有实际用处
// 请求拦截器
https.interceptors.request.use((config) => {

    //以防万一，加个'Access-Control-Allow-Origin':'*'
    config.headers['Access-Control-Allow-Origin'] = '*'

    return config
})

// 响应拦截器
https.interceptors.response.use((response) => {

    return response.data

})

const request = ({ method, url, params, data, headers }) => {
    let config = {
        method,
        url,
        params,
        data,
        headers:{
            ...headers
        }
    }
    method === 'get' ? delete (config, 'data'):delete (config, 'params')

    return https(config)
}


module.exports = {
    request
}